package top.ninwoo.cloudcenter.controller;

import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import top.ninwoo.cloudcenter.service.CloudService;
import top.ninwoo.common.entity.NetworkTopology;
import top.ninwoo.common.entity.SeparatedClusterConfig;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "容器集群管理相关接口")
@RequestMapping("/cluster")
public class ClusterController {

    @Resource
    CloudService cloudService;

    @ApiOperation("下发集群配置")
    @ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", dataType = "List" ,required = true)
    @PostMapping(value = "/sendClusterConfigToEdgeNode")
    public List<SeparatedClusterConfig> sendClusterConfigToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
        // return cloudService.sendClusterConfigToEdgeNode(clusterConfigs);
        return cloudService.sendClusterConfigToEdgeNodeByThreads(clusterConfigs);
    }

    @ApiOperation("删除集群")
    @ApiImplicitParam(name = "clusterId", value = "容器集群ID", defaultValue = "11111", required = true)
    @GetMapping(value = "/removeClusterFromEdgeNode")
    public String removeClusterFromEdgeNode(Long clusterId) {
        boolean res = cloudService.deleteClusterFromEdgeNode(clusterId);
        if(res) {
            return "success";
        }
        return "fail";
    }

    @ApiOperation("获取边缘节点")
    @GetMapping(value = "/getEdgeNodeIds")
    public List<String> getEdgeNodeIds() {
        return cloudService.getEdgeNodeIds();
    }

    @ApiOperation("调整容器集群")
    @ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
    @PostMapping(value = "/adjustCluster")
    public Boolean adjustClusterToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
        return cloudService.adjustCluster(clusterConfigs);
    }

    @ApiOperation("下发容器逻辑拓扑")
    @ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
    @PostMapping(value = "/sendLogicTopo")
    public Boolean sendLogicTopoToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
        return cloudService.sendLogicTopo(clusterConfigs);
    }

    @ApiOperation("调整容器逻辑拓扑")
    @ApiImplicitParam(name = "clusterConfigs", value = "集群配置类", defaultValue = "", required = true)
    @PostMapping(value = "/adjustLogicTopo")
    public Boolean adjustLogicTopoToEdgeNode(@RequestBody List<SeparatedClusterConfig> clusterConfigs) {
        return cloudService.adjustLogicTopo(clusterConfigs);
    }
}
